define(function(require) {
	var $ = require("jquery");
	var justep = require("$UI/system/lib/justep");
	var comUtil = require("$UI/system/components/justep/common/common");

	var Model = function() {
		this.callParent();
		this.renderCount = 0;
	};
	
	Model.prototype.getLeftImageUrl = function(row) {
		var url = row.val("fImg");
		if (row == row.data.getCurrentRow()) {
			url = url.replace(".png", "-1.png");
		}
		return require.toUrl(url);
	};

	Model.prototype.getImageUrl = function(url) {
		return require.toUrl(url);
	};

	Model.prototype.mainMenuDataCustomRefresh = function(event){		         
        var mainMenuData = event.source;
        var childMenuData = this.comp("childMenuData");
        this.getAndLoadCategory("11", "mainCallback",function(data){
        	 mainMenuData.loadData(data);     
             childMenuData.refreshData();//刷新二级菜单列表Data
        });
	};
	
	Model.prototype.childMenuDataCustomRefresh = function(event){
        var mainMenuData = this.comp("mainMenuData");
        if(mainMenuData.getCount() > 0){
        	var pID = mainMenuData.getFirstRow().val("fID");//默认显示第一个根菜单的子菜单
        	var childMenu = this.comp("childMenu");
	        var childMenuData = event.source;
	        this.getAndLoadCategory(pID, "childCallback", function(data){
	        	childMenuData.loadData(data); 
		        childMenu.refresh();//刷新显示二级菜单
	        });
        }
        
	};

	Model.prototype.mainMenuClick = function(event){
		var currentId = this.comp("mainMenuData").getCurrentRowID();
		var childMenuData = this.comp("childMenuData");
		this.getAndLoadCategory(currentId, "childCallback", function(data){
			childMenuData.loadData(data);
		});
	};
		
	
	
    //用于从服务器获取菜单列表并加载
	Model.prototype.getAndLoadCategory = function(pID,jsonpCallback,ajaxCallback){
		$.ajax({
            type: "GET",
            url: "http://101.201.49.208:8080/ex_community/a/api/community/getCategory",
            data:{
            	pID:pID
            }, 
            dataType: 'jsonp',
            cache: false,
            async: false,
            jsonp:"callback",
            jsonpCallback:jsonpCallback,            
            success: ajaxCallback,
            error: function(){
              throw justep.Error.create("加载数据失败");
            }
        });	
	
	}
		
	Model.prototype.childMenuClick = function(event){
	    var currentId = this.comp("childMenuData").getCurrentRowID();
		justep.Shell.showPage("$UI/communityOto/category/categoryInfoList.w?currentId="+currentId );
	};
		
	return Model;
});